<%-- 
    Document   : header
    Created on : Apr 25, 2012, 7:13:56 PM
    Author     : Dell
--%>
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%@ page import="java.util.List"%>  
<%@ page import="java.util.Iterator"%>  
<%@ page import="org.apache.commons.fileupload.*"%>  
<%@ page import="org.apache.commons.fileupload.disk.*"%>  
<%@ page import="org.apache.commons.fileupload.servlet.*"%> 

<%
 out.println( "<div class='wrapper'>");
 out.println( "<div class='header'>");
 out.println( "<a href='index.php' id='image'><img src='images/logo.png' alt='title' height='50'/></a> ");
 out.println( "<h1>RERGag - Just For Laugh</h1>");            
 out.println( "<div class='searchhead'>");
 out.println( "<form method='post' action='search.php'>");
 out.println( "<p> Search Posts!</p>");
 out.println( "<p> Search : <input type='text' name='searchform'/>"); 
 out.println( "<input type='submit' value='Search' /> <br/>");
 out.println( "<input type='checkbox' name='byuser' value='byuser'/> by user_nameH" );
 out.println( "<input type='checkbox' name='bytitletag' value='byjudultag'/> by content title and tag" );
 out.println( "</p>");
 out.println( "</form>");
 out.println( "</div>");
 out.println( "<div class='loginhead' id='loghead'>");
 
 String user_nameH = (String)session.getAttribute("user_nameH");
 String hquery =  "select avatar from user where user_nameH ='"+user_nameH+"' ";

    String driverH = "org.gjt.mm.mysql.driverH";
    Class.forName(driverH).newInstance();

    connection conH=null;
    ResultSet hrst=null;
    Statement hstmt=null;
    
    try{
            String url="jdbc:mysql://localhost:3306/progin_171_13509008?user=root";
            conH= driverManager.getconnection(url);
            hstmt=conH.createStatement();
    }
    catch(Exception e){
            System.out.println(e.getMessage());
    }

    
    if(session.getAttribute("login").equals("true")) //kalau login
                {
                        hrst = hstmt.executeQuery(hquery);
                        hrst.first();
                        String havatar = hrst.getString("avatar"); //ambil avatar
                        
                        out.println( "<form action='logout.jsp'> ");
                        out.println( "<a href='profile.jsp' id='ava'>Your Avatar</a><img src='"+havatar+"' height=50px;/> ");
                        out.println( "Welcome, "+user_nameH+"!<br>" );
                        out.println( "<input type='submit' value='Logout'>");
                        out.println( "</form>");
                    }
                    else
                    {
                        out.println( "<form>");
                        out.println( "<p>Already Registered? Login is just a step away!</p>");
                        out.println( "<p> Username : <input type= 'text' id= 'usr' cols= 1 rows= 1 width = 100 height =  100 /> </p>");
                        out.println( "<p> Password : <input type='password' id='pass' cols= 1 rows= 1 width = 100 height =  100/> </p>");
                        out.println( "<input type='button' value='Login' onclick='demiValidate()' />");
                        out.println( "</form>");
                    }
    
    
 out.println("<div class='links'>");
 out.println("<ul>");
 
 if( session.getAttribute("page") != "registrasi")
    {    
        out.println(" <li><a href='register.jsp' id='registrasi_link'>Registrasi</a></li>" );
    }
 else
    {
        out.println("  <li><a href='register.jsp' id='registrasi_link' class='active'>Registrasi</a></li>");
    }
 
 if(session.getAttribute("page") != "index")
    {
        out.println(" <li><a href='index.jsp' id='home_link'>Home</a></li>"); 
    }
 else
    {
        out.println(" <li><a href='index.jsp' id='home_link' class='active'>Home</a></li>");
    }

 if(session.getAttribute("page") != "konten")
    {
        out.println(" <li><a href='konten.jsp' id='daftar_link'>Konten</a></li>");
    }
 else 
    {
            out.println(" <li><a href='konten.jsp' id='daftar_link' class='active'>Konten</a></li>");
    }
 
 if( session.getAttribute("login").equals("true") &&  !session.getAttribute("page").equals("posting"))
    {
        out.println( "<li><a href='posting.jsp' id='upload_link' >Posting</a></li>");
    }
 else
    {
        out.println( "<li><a href='posting.jsp' id='upload_link' class='active'>Posting</a></li>");
    }
 
 out.println( "</ul>");
 out.println( "</div>");             
 
 out.println( "<script type='text/javascript'>");
 out.println( "function demiValidate() ");
 out.println( "{var user = document.getElementById('usr').value; var pass = document.getElementById('pass').value; validator(user,pass);}");
                 
 out.println( "</script>");
 out.println( "<script type='text/javascript' src='script/validator.js'></script>");
 out.println( "</div></div></div>");
 
%>
